#include "polytope/3D_Space.h"
#include <iostream>

using namespace polytope;
int Space_3D::Dependence_Polytope(Poly_Operation poly_op)

{
	for (int statement_count = 0; statement_count < Statements_list.size(); statement_count ++)
	{//for each statement 
		for (int i = 0; i < ops_store.size(); i++)
		{//for each block in the ops_store
			VBlock *vb = &ops_store[i];
			//std::map<XTMemAddr, std::vector< XTMemAddr > >::iterator cur_address=GLOBAL::ma_st_info.find(ops_store[i].vb_enter_spc);//find the corresponding vector to this vblock;
			vector<XTMemAddr>::iterator cur_write_addr;
			for (cur_write_addr=GLOBAL::ma_st_info[vb->enterSPC()].begin() ; cur_write_addr != GLOBAL::ma_st_info[vb->enterSPC()].end(); cur_write_addr ++)
			{//for each written address
				vector <XTMemAddr>::iterator cur_read_addr;
				int pos = vb->Get_LD_count();
				for (cur_read_addr = GLOBAL::ma_ld_info[vb->enterSPC()].begin() + vb->Get_LD_count(); cur_read_addr != GLOBAL::ma_ld_info[vb->enterSPC()].end(),pos++; ++ cur_read_addr)
				{//for each readed address
					if ((*cur_write_addr) == (*cur_read_addr))
					{//detect the dependence
						this->Statements_list[statement_count].Dependence_Vector.push_back(pos/vb->Get_LD_count());
					}


				}
			}

			
		}
	}
	return 1;
}
